<%@ page language="java" contentType="text/html; charset=utf-8" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.math.BigDecimal" %>
<%
    String requestid = "177641";
    String tablename = "formtable_main_105";//主表
    out.print( "-----requestid-----" + requestid + "<br/>" );
    rs.executeQuery( "select id from " + tablename + " where requestid=?", requestid );
    rs.next();
    int mainid = Util.getIntValue( rs.getString( "id" ), -1 );
    out.print( "-----mainid-----" + mainid + "<br/>" );
    Map<String, String> dataMap = new HashMap<>();
    rs.executeQuery( "select xm,jbxs from " + tablename + "_dt1 where mainid=?", mainid );
    while (rs.next()) {
        String xm = Util.null2String( rs.getString( "xm" ) );
        String jbxs = fMultiply( Util.null2String( rs.getString( "jbxs" ) ), "60" );
        dataMap.put( xm, jbxs );
    }
    out.print( "dataMap=" + dataMap.size() + "<br/>" );
    String sql = " select resourceid,convert(varchar,sum(cast(duration_min as NUMERIC))) duration_min  " +
            "from kq_flow_overtime where computingmode=1 and requestid='"+requestid+"'" +
            "group by requestid,resourceid";
    rs.executeQuery( sql);
    while (rs.next()) {
        String resourceid = Util.null2String( rs.getString( "resourceid" ) );
        String duration_min = Util.null2String( rs.getString( "duration_min" ) );
        out.print( "resourceid = " + resourceid + ", duration_min = " + duration_min + "<br/>" );
        for (Map.Entry<String, String> entry : dataMap.entrySet()) {
            String xmid = entry.getKey();
            String jbxs_min = entry.getValue();
            if (resourceid.equals( xmid ) && !duration_min.equals( jbxs_min )) {
                out.print( "resourceid = " + resourceid + ", duration_min = " +
                        duration_min + ", jbxs_min = " + jbxs_min+ "<br/>" );
            }
        }
    }
%>
<%!
    // 乘法
    public static String fMultiply(String a, String b) {
        a = isZero( a );
        b = isZero( b );
        BigDecimal bg1 = new BigDecimal( a );
        BigDecimal bg2 = new BigDecimal( b );

        BigDecimal bd = bg1.multiply( bg2 );
        return bd.toString();
    }

    public static String isZero(String a) {
        if ("".equals( a )) {
            a = "0";
        }
        return a;
    }

%>